package com.ytjj.qmyx.admin.controller.imController;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.ImSessionInfo;
import com.ytjj.qmyx.admin.model.ImUserBindInfo;
import com.ytjj.qmyx.admin.model.dto.ImUserBindInfoDto;
import com.ytjj.qmyx.admin.model.vo.ImUserBindInfoVO;
import com.ytjj.qmyx.admin.service.imService.ImUserBindInfoService;
import com.ytjj.qmyx.admin.utils.UserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户和客服绑定关系管理controller
 */
@RestController
@RequestMapping("/imUserBind")
@Slf4j
public class ImUserBindInfoController {

    @Autowired
    private ImUserBindInfoService imUserBindInfoService;

    /**
     *  插入由客服填写的客户信息
     * @param imUserBindInfoVO
     * 参数:customerId 客户id
     * @return
     */
    @PostMapping("/insertOrUpdateCustomerMsg")
    public CommonResult insertCustomerMessage(@RequestBody ImUserBindInfoVO imUserBindInfoVO){
        String principal = UserUtil.getPrincipal();
        imUserBindInfoVO.setServiceId(principal);
        Integer count = imUserBindInfoService.insertCustomerMessage(imUserBindInfoVO);
        if (count > 0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    /**
     *  删除客户信息
     * @param imUserBindInfo
     * @return
     */
    @PostMapping("/deleteCustomerMessage")
    public CommonResult deleteCustomerMessage(@RequestBody ImUserBindInfo imUserBindInfo){
        Integer count = imUserBindInfoService.deleteCustomerMessage(imUserBindInfo);
        if (count > 0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     *  回显来访信息中的客户信息
     *  参数:customerId 客户id
     * @return
     */
    @PostMapping("/getCustomerMessage")
    public CommonResult getCustomerMessage(@RequestBody ImUserBindInfoVO imUserBindInfoVO){
        ImUserBindInfoDto imUserBindInfoDto = imUserBindInfoService.selectCustomerMessage(imUserBindInfoVO);
        if (null == imUserBindInfoDto){
            return CommonResult.success(new ImUserBindInfoDto());
        }
        return CommonResult.success(imUserBindInfoDto);
    }
}
